#define _CRT_SECURE_NO_WARNINGS 1
//https://leetcode.cn/problems/count-pairs-whose-sum-is-less-than-target/
class Solution {
public:
    int countPairs(vector<int>& nums, int target)
    {
        sort(nums.begin(), nums.end());
        int left = 0;
        int right = nums.size() - 1;
        int ret = 0;
        while (left < right)
        {
            int sum = nums[left] + nums[right];
            if (sum >= target)
            {
                right--;
            }
            else
            {
                ret += right - left;
                left++;
            }
        }
        return ret;
    }
};


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */

//https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/
class Solution {
public:
    ListNode* trainingPlan(ListNode* head, int cnt)
    {
        ListNode* slow = head, * fast = head;
        while (cnt--)
        {
            fast = fast->next;
        }
        while (fast != nullptr)
        {
            fast = fast->next;
            slow = slow->next;
        }
        return slow;
    }
};